package android.system.monitor;
import java.util.ArrayList;
import java.util.List;

import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.util.Log;
 
/**
 * class name��SmsChoose<BR>
 * class description����ȡ�ֻ��еĸ��ֶ�����Ϣ<BR>
 * PS�� ��ҪȨ�� <uses-permission android:name="android.permission.READ_SMS" /><BR>
 * Date:2012-3-19<BR>
 * 
 * @version 1.00
 * @author CODYY)peijiangping
 */ 
public class SmsContent { 
//    private Activity activity;//�����и�activity���󣬲�֪��Ϊɶ��ǰ����Ҫ�����ھ�Ҫ�ˡ��Լ����԰ɡ� 
    private Context mContext;
    private Uri uri; 
    List<SmsInfo> infos; 
 
//    public SmsContent(Activity activity, Uri uri) { 
//        infos = new ArrayList<SmsInfo>(); 
//        this.activity = activity; 
//        this.uri = uri; 
//    } 
 
    public SmsContent(Context context, Uri uri) { 
        infos = new ArrayList<SmsInfo>(); 
        this.mContext = context; 
        this.uri = uri; 
    } 
 
    /**
     * Role:��ȡ���ŵĸ�����Ϣ <BR>
     * Date:2012-3-19 <BR>
     * 
     * @author CODYY)peijiangping
     */ 
    public List<SmsInfo> getSmsInfo() { 
        String[] projection = new String[] { "_id","thread_id","address", "person", 
                "body", "date", "type", "read","subject" }; 
//        Cursor cusor = activity.managedQuery(uri, projection, null, null, 
//                "date desc"); 
        ContentResolver resolver = mContext.getContentResolver();
        Cursor cusor = resolver.query(uri, projection, null, null, 
                "date desc");
        int idColumn =  cusor.getColumnIndex("_id"); 
        int threadIdColumn = cusor.getColumnIndex("thread_id"); ;
        int nameColumn = cusor.getColumnIndex("person"); 
        int phoneNumberColumn = cusor.getColumnIndex("address"); 
        int smsbodyColumn = cusor.getColumnIndex("body"); 
        int dateColumn = cusor.getColumnIndex("date"); 
        int typeColumn = cusor.getColumnIndex("type"); 
        int readColumn = cusor.getColumnIndex("read");
        int subjectColumn = cusor.getColumnIndex("subject");
//        values.put("address", phoneNumber);    
//		 values.put("body", content);    
//		 values.put("thread_id", -2);d
//		 values.put("person", "-2");
//		 values.put("protocol", -2);
//		 values.put("subject", "-2");
//		 values.put("status", -2);
        
        String kk[] = cusor.getColumnNames();
        if (cusor != null) { 
            while (cusor.moveToNext()) { 
                SmsInfo smsinfo = new SmsInfo(); 
                smsinfo.setId( cusor.getLong(idColumn));
                if(threadIdColumn>=0)
                	smsinfo.setThread_id(cusor.getLong(threadIdColumn));
                smsinfo.setName(cusor.getString(nameColumn)); 
                smsinfo.setDate(cusor.getString(dateColumn)); 
                smsinfo.setPhoneNumber(cusor.getString(phoneNumberColumn)); 
                smsinfo.setSmsbody(cusor.getString(smsbodyColumn)); 
                smsinfo.setType(cusor.getString(typeColumn)); 
                smsinfo.setRead(cusor.getString(readColumn));
                smsinfo.setSubject(cusor.getString(subjectColumn));
                infos.add(smsinfo); 
                
               // Log.e("ooooo", "subject="+cusor.getString(cusor.getColumnIndex("subject"))+
              //  Log.e("ooooo", 		"  person="+cusor.getString(cusor.getColumnIndex("person"))
                	//	"status="+cusor.getString(cusor.getColumnIndex("status"))+
                		//" protocol"+cusor.getString(cusor.getColumnIndex("protocol"))+
                		//" thread_id="+cusor.getString(cusor.getColumnIndex("thread_id"))
                		//);
            } 
            cusor.close(); 
        } 
        return infos; 
    } 
} 

